package com.design.testdemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.design.testdemo.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @Auther: Timmy
 * @Data: 2017/6/7
 * @Fuction:
 */

public class RecycleViewAdapter extends RecyclerView.Adapter {

    private List<Integer> mList = new ArrayList<>();

    private Context mContext;

    public RecycleViewAdapter(Context context) {
        mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_info, parent, false);
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        int integer = mList.get(position);
        ((ViewHolder) holder).setData(integer);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void setData(int data) {
        //mList = data;
        mList.add(data);
        notifyDataSetChanged();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_time)
        TextView mTvTime;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void setData(int data) {
            mTvTime.setText("" + data);
        }
    }
}
